export function transform(sNodes, id, pid, children) {
  let i
  let l
  const key = id// 自身id
  const parentKey = pid// 父id
  const childKey = children// 子
  if (!key || key === '' || !sNodes) return []
  if (Object.prototype.toString.call(sNodes) === '[object Array]') {
    const r = []
    const tmpMap = []
    for (i = 0, l = sNodes.length; i < l; i++) {
      tmpMap[sNodes[i][key]] = sNodes[i]
    }
    for (i = 0, l = sNodes.length; i < l; i++) {
      if (tmpMap[sNodes[i][parentKey]] && sNodes[i][key] !== sNodes[i][parentKey]) {
        if (!tmpMap[sNodes[i][parentKey]][childKey]) { tmpMap[sNodes[i][parentKey]][childKey] = [] }
        tmpMap[sNodes[i][parentKey]][childKey].push(sNodes[i])
      } else {
        r.push(sNodes[i])
      }
    }
    return r
  } else {
    return [sNodes]
  }
}
